﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DomainModel.Entities;
using FluentNHibernate.Mapping;

namespace DomainModel.ClassMaps
{
    public class UserClassMap : ClassMap<User>
    {
        public UserClassMap()
        {
            Table("UserInfo");
            Id(x => x.UserId, "user_id").GeneratedBy.Native();

            Map(x => x.Age, "age").Nullable();
            Map(x => x.City, "city").Nullable();
            Map(x => x.Login, "login").Not.Nullable().Length(50);
            Map(x => x.Password, "password").Not.Nullable().Length(40);

            Component(x => x.StatusInfo,
                m =>
                {
                    m.Map(x => x.Description, "description").Nullable().Length(1000);
                    m.Map(x => x.Status, "status_id");
                }
            );

            HasMany(x => x.MyUndeliveredMessages).Cascade.All();
            HasMany(x => x.UndeliveredMessagesToMe).Cascade.All();

            HasManyToMany<User>(x => x.Friends)
                .Table("UserFriendsList")
                .ParentKeyColumn("owning_user_id")
                .ChildKeyColumn("friend_user_id");

        }
    }
}
